{% include "header.html" %}

<div class="container">
    <div class="box box-success">
        <div class="box-header">
            <h4 class="box-title"><span class="fa fa-pencil-square-o"></span>修改密码</h4>
        </div>
        <div class="box-body">
            <form method="post" class="form-horizontal">
                <input type="hidden" id="sid" name="stu_id" value="{{ stu.stu_id }}">
                <div class="form-group">
                    <label for="new_pass" class="control-label col-lg-2 col-sm-2 col-xs-4">新密码</label>
                    <div class="col-lg-10 col-sm-10">
                        <input type="password" name="stu_pass" id="new_pass" class="form-control" required>
                    </div>
                </div>
                <div class="form-group">
                    <label for="two_pass" class="control-label col-lg-2 col-sm-2 col-xs-4">确定密码</label>
                    <div class="col-lg-10 col-sm-10">
                        <input type="password" id="two_pass" class="form-control" required>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-lg-12" style="margin-top: 5px;">
                        <button type="submit" class="btn btn-info btn-block">确认修改</button>
                    </div>
                </div>
            </form>
            {% include "sign.html" %}
        </div>
    </div>
</div>

<script>
    $('form').submit(function (e) {
        e.preventDefault();
        var sid = $('#sid').val().trim();
        var new_pass = $('#new_pass').val().trim();
        var two_pass = $('#two_pass').val().trim();
        if (new_pass.length < 6) {
            alert("密码不能小于6位！");
        } else if (/\W/.test(new_pass)) {
            alert("密码不能存在中文！");
        } else if (two_pass !== new_pass) {
            alert("两次密码不相同！");
        } else {
            $.post('/change', {
                stu_id: sid,
                stu_pass: new_pass
            }, function (data) {
                if (data.status) {
                    alert('SUCCESS: 修改成功！');
                    location.href = '/login'
                } else {
                    alert('ERROR: 修改失败！'+data.msg);
                }
            });
        }
    });
</script>

</body>
</html>